// page/member/profile.js
var utils = require("../../utils/util.js")
Page({
    data: {
        isHide: 0,
        thumb: '',
        nickname: '',
        endDate: utils.formatDate(new Date)
    },

    onLoad: function (options) {
        var that = this
        wx.getUserInfo({
            success: function (res) {
                that.setData({
                    isHide: 1,
                    thumb: res.userInfo.avatarUrl,
                    nickname: res.userInfo.nickName,
                    profile: {
                        birthday: "",
                        sex: "",
                        phone: ""
                    }
                })
            }
        })
    },
    bindSex: function(){
        var that = this
        wx.showActionSheet({
            itemList: ["男","女"],
            success: function(res){
                if(res.tapIndex==0){
                    that.setData({
                        "profile.sex": "男"
                    })
                }else{
                    that.setData({
                        "profile.sex": "女"
                    })                    
                }
            },
            fail: function(res){

            }
        })
    },
    bindDateChange: function (e) {
        this.setData({
            "profile.birthday": e.detail.value
        })
    },
    bindPhone: function (e) {
        this.setData({
            "profile.phone": e.detail.value
        })
    },
    formSubmit: function (e) {
        var that = this 
        var birthday = that.data.profile.birthday
        var sex = that.data.profile.sex
        var phone = that.data.profile.phone
        if (!birthday || !sex || !phone){
            wx.showModal({
                title: '提示',
                content: '请完善个人信息'
            })
        } else if (phone.length<11){
            wx.showModal({
                title: '提示',
                content: '请填写正确的手机号码',
            })
        }else{
            utils.showSuccess("保存成功", 5000)
        }
    }
})